package com.situ.sys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.util.entity.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.sys.service.SysRoleService;
import com.situ.sys.entity.SysRole;
import com.situ.util.*;

import java.util.List;

/**
 * SysRole的路由接口服务
 * 
 * @author 
 *
 */
@RestController
public class SysRoleController {

	/** SysRoleService服务 */
	@Autowired
	private SysRoleService sysRoleService;
	
	/**
	 * 查询所有SysRole数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "querySysRole", produces = {"application/json;charset=UTF-8"})
	public ResponseData find(SysRole value) {

		return ResponseData.ok().putDataValue("list",sysRoleService.find(value));
	}
	
	/**
	 * 通过id查询SysRole数据的方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "querySysRoleById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData findOne(@PathVariable(name="id") Integer id) {
		 return ResponseData.ok().putDataValue("obj",sysRoleService.findOne(id));
	}
	
	/**
	 * 插入SysRole属性不为空的数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "saveSysRole")
	public ResponseData save(SysRole value) {
		return ResponseData.ok().putDataValue("obj", sysRoleService.saveNotNull(value));
	}
	
	/**
	 * 更新SysRole属性不为空的数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "updateSysRole", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(SysRole value) {
		return ResponseData.ok().putDataValue("obj",sysRoleService.updateNotNullById(value));
	}

	/**
	 * 通过id删除SysRole数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delSysRoleById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delete(@PathVariable(name="id") Integer id) {
		return ResponseData.ok().putDataValue("obj",sysRoleService.deleteById(id));
	}

	@RequestMapping(value = "queryallSysRole", produces = {"application/json;charset=UTF-8"})
	public ResponseData find2(SysRole value,
							  @RequestParam(defaultValue ="1", required = false) int startPage ,
							  @RequestParam(defaultValue = "5",required = false) int PageSize) {
		PageHelper.startPage(startPage,PageSize );
		List<SysRole> list = sysRoleService.selectallrole(value);
		PageInfo pageInfo=new PageInfo(list,5);
		return ResponseData.ok().putDataValue("pageInfo",pageInfo);
	}
}
